package com.android.svmc.app.mobile.controller;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class WifiManagement {
	/* A class a implementation comment can goes here */
	private static WifiManager wifi;
	private static WifiManagement me;
	//private static INotifyReceiver parent;
	private static Context context;
	private WifiManagement(Context context)
	{
		this.context = context;
		wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		//this.parent = parent;
	}
	public static WifiManagement getInstance(Context context)
	{
			me = new WifiManagement(context);
		return me;
	}

	public static boolean checkStatusWifi()
	{
		boolean flag = false;
		final ConnectivityManager connMgr = (ConnectivityManager)
		context.getSystemService(Context.CONNECTIVITY_SERVICE);
	
		final android.net.NetworkInfo wifi =
		connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
	
		final android.net.NetworkInfo mobile =
		connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
	
		if( wifi.isAvailable() ){
			//Toast.makeText(context, "Wifi" , Toast.LENGTH_LONG).show();
			flag = true;
		}
		else if( mobile.isAvailable() ){
			//Toast.makeText(context, "Mobile 3G " , Toast.LENGTH_LONG).show();
			flag = true;
		}
		return flag;

	}
	
	public static boolean haveNetworkConnection() {
	    boolean haveConnectedWifi = false;
	    boolean haveConnectedMobile = false;

	    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
	    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
	    for (NetworkInfo ni : netInfo) {
	        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
	            if (ni.isConnected())
	                haveConnectedWifi = true;
	        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
	            if (ni.isConnected())
	                haveConnectedMobile = true;
	    }
	    return haveConnectedWifi || haveConnectedMobile;
	}
}
